package com.search.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.search.pojo.ProjectInfo;
import com.search.pojo.ResultDemo;
import com.search.service.ProjectInfoService;
import com.search.utils.MyDigestUtil;

@RestController
public class ProjectInfoController {
 @Autowired
 private ProjectInfoService projectInfoService;
 @RequestMapping("/bfxmshow")
  public List<Map<String,Double>> findProject(@RequestParam Integer id){
	  int i =projectInfoService.selectById(id);
	  double d =i;
	 Map<String,Double> map =new HashMap<>();
	 map.put("value", d/100);
	 List<Map<String,Double>> result =new ArrayList<>();
	 result.add(map);
	  return result;
  }
 
 @RequestMapping("/xmshow")
 public List<Map<String,Integer>> findProjectTest(@RequestParam Integer id){
	 int i =projectInfoService.selectById(id);
	 Map<String,Integer> map =new HashMap<>();
	 map.put("value", i);
	 List<Map<String,Integer>> result =new ArrayList<>();
	 result.add(map);
	 return result;
 }
 
 @RequestMapping("/allin")
 public List<ResultDemo> selectAll(){
	 List<ProjectInfo> list =projectInfoService.selectAll();
	 List<ResultDemo> result=new ArrayList<>();
	 for(ProjectInfo info:list){
		 ResultDemo demo =new ResultDemo();
		 demo.setTitle(info.getTitle());
		 demo.setProgress(String.valueOf(info.getProgress())+"%");
		 demo.setEnddt(MyDigestUtil.dateFormate(info.getEnddt()));
		 result.add(demo);
	 }
	 return result;
 }
 /**
  * 
  */
 @RequestMapping(value="/getWeather",produces ="application/json; charset=utf-8")
 public String getWeather(){
	 String url = "http://jisutqybmf.market.alicloudapi.com/weather/query";
	 String appcode = "bd3c8717cbde43799114798230a6242c";
	 Map<String, String> querys = new HashMap<String, String>();
	 querys.put("city", "江津");
	 String response = MyDigestUtil.doGet(url,"APPCODE " + appcode,querys);
	 return response; 
 }
}
